package io.jsen.meta.diff.context;


import io.jsen.meta.diff.obj.base.*;
import io.jsen.meta.diff.obj.ext.*;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;

/**
 * @author jsen
 * @date 2021/4/6
 */
class DefaultMetaConvertInit {

    @SuppressWarnings("rawtypes")
    static void register() {
        MetaContext.registerConvert(Boolean.class,
                MetaBoolean::new);
        MetaContext.registerConvert(Byte.class,
                MetaByte::new);
        MetaContext.registerConvert(Character.class,
                MetaChar::new);
        MetaContext.registerConvert(Double.class,
                MetaDouble::new);
        MetaContext.registerConvert(Enum.class,
                MetaEnum::new);
        MetaContext.registerConvert(Float.class,
                MetaFloat::new);
        MetaContext.registerConvert(Integer.class,
                MetaInteger::new);
        MetaContext.registerConvert(Long.class,
                MetaLong::new);
        MetaContext.registerConvert(Short.class,
                MetaShort::new);
        MetaContext.registerConvert(String.class,
                MetaString::new);


        MetaContext.<MetaBoolean, Boolean>registerConvert(MetaBoolean.class,
                (field, s) -> s.getVal());
        MetaContext.<MetaByte, Byte>registerConvert(MetaByte.class,
                (field, s) -> s.getVal());
        MetaContext.<MetaChar, Character>registerConvert(MetaChar.class,
                (field, s) -> s.getVal());
        MetaContext.<MetaDouble, Double>registerConvert(MetaDouble.class,
                (field, s) -> s.getVal());
        MetaContext.<MetaEnum, Enum>registerConvert(MetaEnum.class,
                (field, s) -> s.getVal());
        MetaContext.<MetaFloat, Float>registerConvert(MetaFloat.class,
                (field, s) -> s.getVal());
        MetaContext.<MetaInteger, Integer>registerConvert(MetaInteger.class,
                (field, s) -> s.getVal());
        MetaContext.<MetaLong, Long>registerConvert(MetaLong.class,
                (field, s) -> s.getVal());
        MetaContext.<MetaShort, Short>registerConvert(MetaShort.class,
                (field, s) -> s.getVal());
        MetaContext.<MetaString, String>registerConvert(MetaString.class,
                (field, s) -> s.getVal());


        // 扩展
        MetaContext.registerConvert(BigDecimal.class,
                MetaBigDecimal::new);
        MetaContext.registerConvert(BigInteger.class,
                MetaBigInteger::new);
        MetaContext.registerConvert(Date.class,
                MetaDate::new);
        MetaContext.registerConvert(LocalDate.class,
                MetaLocalDate::new);
        MetaContext.registerConvert(LocalTime.class,
                MetaLocalTime::new);
        MetaContext.registerConvert(LocalDateTime.class,
                MetaLocalDateTime::new);

        MetaContext.<MetaBigDecimal, BigDecimal>registerConvert(MetaBigDecimal.class,
                (field, s) -> s.getVal());
        MetaContext.<MetaBigInteger, BigInteger>registerConvert(MetaBigInteger.class,
                (field, s) -> s.getVal());
        MetaContext.<MetaDate, Date>registerConvert(MetaDate.class,
                (field, s) -> s.getVal());
        MetaContext.<MetaLocalDate, LocalDate>registerConvert(MetaLocalDate.class,
                (field, s) -> s.getVal());
        MetaContext.<MetaLocalTime, LocalTime>registerConvert(MetaLocalTime.class,
                (field, s) -> s.getVal());
        MetaContext.<MetaLocalDateTime, LocalDateTime>registerConvert(MetaLocalDateTime.class,
                (field, s) -> s.getVal());
    }

    private DefaultMetaConvertInit() {
    }
}
